package com.careercup.question.id14967961;

import java.util.AbstractQueue;
import java.util.Iterator;
import java.util.Queue;
import java.util.Scanner;

public class Solution {
	private static class CircularQueue<E> extends AbstractQueue<E> {
		Object[] elems;
		int f = 0, r = 0, c = 0;
		public CircularQueue(int initialCapacity) {
			elems = new Object[initialCapacity];
		}
		
		private boolean isFull() {
			return size() == elems.length;
		}
		
		@Override
		public synchronized boolean offer(E e) {
			if(isFull())
				return false;
			elems[r] = e;
			r = (r + 1) % elems.length;
			c++;
			return true;
		}

		@Override
		public E peek() {
			if(!isEmpty())
				return (E)elems[f];
			return null;
		}

		@Override
		public synchronized E poll() {
			if(!isEmpty()) {
				int t = f;
				f = (f + 1) % elems.length;
				c--;
				return (E)elems[t];
			}
			return null;
		}

		@Override
		public Iterator<E> iterator() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int size() {
			return c;
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Queue<Integer> q = new CircularQueue<Integer>(10);
		Scanner in = new Scanner(System.in);
		while(in.hasNext()) {
			String op = in.next();
			if(op.equalsIgnoreCase("a"))
				q.offer(in.nextInt());
			else if(op.equalsIgnoreCase("r"))
				System.out.println(q.poll());
		}
	}
}
